import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName LC728
 * @Author ykx
 * @Date 2024/3/30 13:14
 * @Version 1.0
 */
public class LC728 {
    public static void main(String[] args) {
        LC728 lc728 = new LC728();
        System.out.println(lc728.selfDividingNumbers(1, 22));
    }

    public List<Integer> selfDividingNumbers(int left, int right) {
        List<Integer> result = new ArrayList<>();
        for (int i = left; i <= right; i++) {
            String s = i + "";
            if (s.length() == 1) {
                // 一位数一定是自除数
                result.add(i);
            } else if (s.contains("0")) {
                // 自除数没有0
                continue;
            } else {
                boolean flag = true;
                for (int j = 0; j < s.length(); j++) {
                    if (i % (s.charAt(j) - '0') != 0) {
                        flag = false;
                        break;
                    }
                }
                if (flag) {
                    result.add(i);
                }
            }
        }
        return result;
    }
}
